from etgui import *
from PageLayout import *
from PrefsMirrorEntries import 	MakeItemAdditionalIncludeDirectives,\
								MakeItemUseMakeSupport,				\
								MakeItemMakeCommand,				\
								MakeItemHelpTarget,					\
								MakeItemRecursiveMakeDirs
from AllListEditors import GeneralListEditor

gTabSheets=[]   # for language sensitive behavior
 
def MakePageBuild(model):
	return MakePageLayout(eVObjHExpand|eVObjVCenter,
		MakeBorderedSectionLayout("Options",
			MakeItemUseMakeSupport(model,"MakefileSupport"),
			Form(
				items=MakeItemMakeCommand(model,"MakeCommand")
			),
			Form(
				items=MakeItemHelpTarget(model,"HelpTarget")
			)
		)
	)

def MakePageBuildProjectTargets(model):
	cppPage=TabPage(
		"Ansi C/C++",
		MakePageLayout(eVObjHExpand|eVObjVCenter,
			MakeSectionLayout(
				Form( 
					items=[
						"Executable",PotTextField("ExecTarget"),
						"+ Libraries Linked",PotTextField("ExecOtherLibs"),
						"Relinkable Object",PotTextField("RelinkTarget"),
						"+ Libraries Linked",PotTextField("RelinkOtherLibs"),
						"Library",PotTextField("LibTarget"),
						"Shared Library",PotTextField("SharedLibTarget"),
						"Other",PotTextField("OtherTarget")
					]
				),
			)
		)
	)
	javaPage=TabPage(
		"Java",
		MakePageLayout(eVObjHExpand|eVObjVCenter,
			MakeSectionLayout(
				Form( 
					items=[
						"Application Class",PotTextField("JavaApplicationTarget"),
						"Applet Class(es)",PotTextField("JavaAppletClasses"),
						"HTML File",PotTextField("JavaHtmlTarget"),
						"Library (JAR)",PotTextField("JavaLibTarget"),
						"+ JAR Filelist",PotTextField("JavaLibTargetFiles"),
						"Target Class(es)",PotTextField("JavaTargetTarget")
						##"Other",PotTextField("JavaOtherTarget")
					]
				)
			)
		)
	)
	tabSheet=MakeTabSheetLayout(cppPage,javaPage)
	global gTabSheets
	gTabSheets.append((tabSheet,cppPage,javaPage))
	return tabSheet

def MakePageBuildBuildStructure(model):
	list_editor=GeneralListEditor(model,"JavaClasspath","Classpath",';',3)
	edit_button=ActionButton("Edit...",action=list_editor)
 
	linkObjects=PotGuiPopupButton("LinkObjects")
	linkObjects.AddItem("None",0)
	linkObjects.AddItem("Relinkable Object",1)
	linkObjects.AddItem("Library",2)
	linkObjects.AddItem("Object Files + Received",3)
	linkObjects.AddItem("Received Targets",4)
	projectLibs=PotTextField("GenProjectLibs")
	projectLibs.Disable()
	AddSplitFieldTip(projectLibs," ")
	cppPage=TabPage(
		"Ansi C/C++",
		MakePageLayout(eVObjHExpand|eVObjVCenter,
			MakeSectionLayout(
				Form( 
					items=[
						"Passed to Superproject",MakeFieldLayout(linkObjects),   # XXX
						"Received from Subprojects",projectLibs
					]+MakeItemRecursiveMakeDirs(model,"SubDirs")
				)
			)
		)
	)
 
	java_source_rel=PotGuiActionButton("PSEUDO.Action.GenJavaSourceDir","Generate...")
	java_gen_root_rel=PotGuiActionButton("PSEUDO.Action.GenJavaGenerateDir","Generate...")
	javaPage=TabPage(
		"Java",   # page selector
		MakePageLayout(eVObjHExpand|eVObjVCenter,
			MakeBorderedSectionLayout("Class Path to",
				Form( 
					items=[
						"Libraries",FieldWithButtonLayout(PotTextField("JavaClasspath"),edit_button),
						"Source Package Root",FieldWithButtonLayout(PotTextField("JavaSourceDir"),java_source_rel),
						"Byte-Code Package Root",FieldWithButtonLayout(PotTextField("JavaGenerateDir"),java_gen_root_rel),
					]
				)
			),
			MakeBorderedSectionLayout("Make",
				Form( 
					items=MakeItemRecursiveMakeDirs(model,"SubDirs")
				)
			)
		)
	)
 
	tabSheet=MakeTabSheetLayout(cppPage,javaPage)
	global gTabSheets
	gTabSheets.append((tabSheet,cppPage,javaPage))
	return tabSheet

def MakePageBuildAdvanced(model):
	enableItem=Form(
		items=[
			" Other Directory",
			PotGuiEnabler(
				"UseLocationMakeSupport",
				PotExpandedTextField(model,"LocationMakeSupport"),
			)
		]
	)
	dir=PotGuiOneOf("UseLocationMakeSupport")
	dir.AddItem("Use Generated Files Directory",0)
	dir.AddVObject(enableItem,1)
	enablePath="MakefileSupport"
	dir=PotGuiEnabler(
		enablePath,
		dir
	)
	enableItem1=PotGuiEnabler(
		enablePath,
		Form(
			items=[
				"Dependencies",PotTextField("DependenciesFile"),
				"Macros",PotTextField("MacrosFile"),
				"Include File List",PotTextField("IncludeFilesFile")
			]
		)
	)
	enableItem2=PotGuiEnabler(
		enablePath,
		PotGuiToggleButton("UseIncludeDir","Use Include Directives for Dependencies Generation"),
	)
	return MakePageLayout(eVObjHExpand|eVObjVCenter,
		MakeBorderedSectionLayout("Make Support Files Directory",
			dir,
		),
		MakeBorderedSectionLayout("Make Support Files",
			enableItem1,
			Filler(gPoint8),
			enableItem2,
		)
	)
 
def SwitchToLanguageTabPages(lang):
	for (sheet,cpppage,javapage) in gTabSheets:
		if lang=="java":
			sheet.ShowPage(javapage)
		else:   # lang=="cpp"
			sheet.ShowPage(cpppage)
 
